package data;

import java.sql.*;


import domain.Donador;

public class JDBCDonadorDAO implements IDonadorDAO{

	
	public Donador select(Connection conn, int donadorOID) {
		PreparedStatement stmt = null;
        ResultSet result = null;
        Donador d = null;
        String sql = "SELECT * FROM Donador WHERE (donadorOID = ?) ";

        try {
            stmt = conn.prepareStatement(sql);
            stmt.setInt(1, donadorOID);
            result = stmt.executeQuery();

            result.next();
            d = new Donador();
            d.setDni(result.getString("dni"));
            d.setNombre(result.getString("nombre"));
            d.setApellidos(result.getString("apellidos"));
            d.setDireccion(result.getString("apellidos"));
            d.setNick(result.getString("nick"));
            d.setPass(result.getString("pass"));
            d.setFechaNacimiento(result.getDate("fechaNacimiento"));
            d.setDonacionesRealizadas(null);
            
        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            try {
                if (result != null) {
                    result.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException e) {
            }
        }
        return d;
	}

}
